home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvipj / dvipj.c < prev    next >
C/C++ Source or Header  |  1992-04-08  |  13KB  |  410 lines

  1. /* -*-C-*- dvipj.c */
  2. /*-->dvijet*/
  3. /**********************************************************************/
  4. /******************************* dvipj ********************************/
  5. /**********************************************************************/
  6.  
  7.  /* HP PaintJet driver based on dvijet (the escape sequences are very */
  8.  /* similar), magnification stuff from dvitos (also 180 dpi) */
  9.  
  10.  /* The changes to the included files have *only* been made for */
  11.  /* unsegmented-memory un*x */
  12.  
  13.  /* We allow 4 colours (including black, but not including white) 
  14.     (NPLANES =4), stored as 4 separate bitmaps.  The current bitmap is 
  15.     indexed by global variable `plane', which can be reset by \specials.  To 
  16.     make things simpler, the paintjet palette is redefined so that 
  17.     when only one bitmap has a pixel set at the appropriate position 
  18.     you get the right colour.  At present, if more then one bitmap has 
  19.     a given pixel set, you get a colour determined by the sequence 
  20.     red, green, blue, black (in order of increasing precedence).  This 
  21.     should be changed by removing corresponding entries in the other 
  22.     bitmaps when the current colour is painted. 
  23.     There is one \special{color <red|blue|green|black>}.
  24.     Transparency mode is assumed -- this should be a command-line
  25.     switch.
  26.  */
  27.  
  28. #include "dvihead.h"
  29.  
  30. /**********************************************************************/
  31. /************************  Device Definitions  ************************/
  32. /**********************************************************************/
  33.  
  34. /* All output-device-specific definitions go here.  This section must
  35. be changed when modifying a dvi driver for use on a new device */
  36.  
  37. #undef HPPAINTJET
  38. #define  HPPAINTJET       1        /* conditional compilation flag */
  39.  
  40. #define VERSION_NO    "2.10"        /* DVI driver version number */
  41.  
  42. #define  DEVICE_ID    "Hewlett-Packard PaintJet printer"
  43.                 /* this string is printed at runtime */
  44.  
  45. #define OUTFILE_EXT    "pj"
  46.  
  47. #define  DEFAULT_RESOLUTION 180        /* default dots/inch on HP PaintJet */
  48.  
  49. #define  BYTE_SIZE        8        /* output file byte size */
  50.  
  51. #undef STDRES
  52. #define STDRES  0            /* 0 for low-resolution devices */
  53.  
  54. #define  XDPI        180        /* HP Laser Jet horizontal dots/inch */
  55. #define  XPSIZE        8        /* horizontal paper size in inches */
  56.  
  57. #define  XSIZE        (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\
  58.                 (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE))
  59.                     /* number of horizontal dots; */
  60.                     /* MUST BE multiple of */
  61.                     /* 2*HOST_WORD_SIZE */
  62. #define  XWORDS        ((XSIZE + HOST_WORD_SIZE - 1)/HOST_WORD_SIZE)
  63.                     /* number of words in rows  */
  64.                     /* of bitmap array */
  65.  
  66. #define  YDPI        180        /* HP PaintJet vertical dots/inch */
  67.  
  68. #define  YPSIZE        11        /* vertical paper size in inches */
  69. #define  YSIZE        (YDPI*YPSIZE)    /* number of vertical dots */
  70. #define  NPLANES        4               /* number of colour planes
  71.                        (including black) */
  72. /* The printer bit map (must have an even number of columns). */
  73.  
  74. #define XBIT ((1+2*XWORDS)/2)
  75. #define YBIT YSIZE
  76. #if    (IBM_PC_LATTICE | IBM_PC_MICROSOFT | IBM_PC_WIZARD)
  77. #undef SEGMEM
  78. #define SEGMEM 1 /* ( ((long)XBIT * (long)YBIT) > 65536L ) */
  79. #endif
  80.  
  81. #include "bitmap.h"
  82.  
  83. #include "main.h"
  84. #include "abortrun.h"
  85. #include "actfact.h"
  86. #include "alldone.h"
  87. #include "chargf.h"
  88. #include "charpk.h"
  89. #include "charpxl.h"
  90. #include "clrbmap.h"
  91. #include "clrrow.h"
  92. #include "dbgopen.h"
  93.  
  94. /*-->devinit*/
  95. /**********************************************************************/
  96. /****************************** devinit *******************************/
  97. /**********************************************************************/
  98.  
  99. void
  100. devinit(argc,argv)        /* initialize device */
  101. int argc;
  102. char *argv[];
  103. {
  104.     (void)getbmap();
  105.     OUTF("\033E\033*t%dR",(int)hpres);    /* printer reset, resolution */
  106.     OUTS("\033&k3W");        /* transparency mode -- should be made */
  107.                 /* optional */
  108. }
  109.  
  110. /*-->devterm*/
  111. /**********************************************************************/
  112. /****************************** devterm *******************************/
  113. /**********************************************************************/
  114.  
  115. void
  116. devterm()            /* terminate device */
  117. {
  118. }
  119.  
  120. #include "dvifile.h"
  121. #include "dviinit.h"
  122. #include "dviterm.h"
  123. #include "dispchar.h"
  124. #include "f20open.h"
  125. #include "fatal.h"
  126. #include "fillrect.h"
  127. #include "findpost.h"
  128. #include "fixpos.h"
  129. #include "fontfile.h"
  130. #include "fontsub.h"
  131. #include "getbmap.h"
  132. #include "getbytes.h"
  133. #include "getfntdf.h"
  134. #include "getpgtab.h"
  135. #include "initglob.h"
  136. #include "inch.h"
  137. #include "loadchar.h"
  138. #include "movedown.h"
  139. #include "moveover.h"
  140. #include "moveto.h"
  141. #include "nosignex.h"
  142. #include "openfont.h"
  143. #include "option.h"
  144.  
  145. /*-->outline*/
  146. /**********************************************************************/
  147. /****************************** outline *******************************/
  148. /**********************************************************************/
  149.  
  150. void
  151. outline(type,pbit)
  152. UNSIGN32 *pbit;                /* pointer to raster line */
  153. char type;            /* 'V' or 'W' for non-last or last */
  154.                 /* plane respectively */
  155.  
  156. /*************************************************************************
  157. Use machine-specific coding here for efficiency.  For TOPS-20, we encode
  158. 9 bytes from every pair  of 36-bit words.
  159.  
  160. For each raster line on the paper, the Laser Jet expects a binary  8-bit
  161. byte stream of the form
  162.  
  163.     <ESC>*bnnnWxxxxxxx ... xxxxxxx
  164.                <--- nnn bytes --->
  165.  
  166. where each byte contains, in order from high to low bit, a left-to-right
  167. bit pattern.  No  end-of-line marker  is required;  the escape  sequence
  168. automatically causes a new raster line to be started.
  169. *************************************************************************/
  170.  
  171. {
  172.     register UNSIGN32 w_even,w_odd;
  173.     register UNSIGN32 *p;
  174.     register BYTE *pbuf;
  175.     BYTE buf[1+(XSIZE+7)/8];        /* space for EOS + n 8-bit bytes */
  176.     register INT16 i,last_word;
  177.  
  178.  
  179. #if    IBM_PC_MICROSOFT
  180.     for (last_word = XBIT - 1;
  181.     (last_word >= 1) && (*(UNSIGN32*)normaddr(pbit,last_word) == 0);
  182.     --last_word)
  183.         ;                /* trim white space a word at a time */
  184. #else
  185.     p = pbit + XBIT - 1;        /* point to last word on line */
  186.     for (last_word = XBIT - 1; (last_word >= 1) && (*p == 0); --last_word)
  187.         --p;                /* trim white space a word at a time */
  188. #endif
  189.  
  190.     p = pbit;
  191.     pbuf = &buf[0];
  192.     for (i = 0; i <= last_word; i += 2)    /* loop over trimmed raster */
  193.     {
  194.         w_even = (*p++);
  195.         w_odd = (*p++);
  196.  
  197. #if    (HOST_WORD_SIZE == 36)
  198.     *pbuf++ = (BYTE)( (w_even >> 28) & 0xff);
  199.     *pbuf++ = (BYTE)( (w_even >> 20) & 0xff);
  200.     *pbuf++ = (BYTE)( (w_even >> 12) & 0xff);
  201.     *pbuf++ = (BYTE)( (w_even >>  4) & 0xff);
  202.     *pbuf++ = (BYTE)( ((w_even <<  4) | (w_odd >> 32)) & 0xff);
  203.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  204.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  205.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  206.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  207. #else /* HOST_WORD_SIZE == 32 */
  208.     /* encode 8 bytes at a time on 32-bit machines */
  209.     *pbuf++ = (BYTE)( (w_even >> 24) & 0xff);
  210.     *pbuf++ = (BYTE)( (w_even >> 16) & 0xff);
  211.     *pbuf++ = (BYTE)( (w_even >>  8) & 0xff);
  212.     *pbuf++ = (BYTE)( (w_even      ) & 0xff);
  213.     *pbuf++ = (BYTE)( (w_odd  >> 24) & 0xff);
  214.     *pbuf++ = (BYTE)( (w_odd  >> 16) & 0xff);
  215.     *pbuf++ = (BYTE)( (w_odd  >>  8) & 0xff);
  216.     *pbuf++ = (BYTE)( (w_odd       ) & 0xff);
  217. #endif
  218.  
  219.     }
  220.  
  221.     *pbuf = '\0';            /* trailing EOS marker */
  222.  
  223.     last_word |= 1;            /* make last_word ODD */
  224.     for (i = ((last_word+1)*HOST_WORD_SIZE)/8;
  225.         (*(--pbuf) == '\0') && (i > 1); --i)
  226.     ;    /* trim trailing zero bytes, leaving at least one */
  227.     last_word = i;
  228.  
  229.     if (type=='V')
  230.       OUTF("\033*b%dV",(int)last_word);
  231.     else if (type=='W')
  232.       OUTF("\033*b%dW",(int)last_word);
  233.     pbuf = &buf[0];    /* cannot use fprintf with %s format because of
  234.                    NUL's in string, and it is slow anyway */
  235.     for (i = 0; i < last_word; ++pbuf,++i)
  236.         OUTC(*pbuf);
  237. }
  238.  
  239. /*-->prtbmap*/
  240. /**********************************************************************/
  241. /****************************** prtbmap *******************************/
  242. /**********************************************************************/
  243.  
  244. void
  245. prtbmap()
  246.  
  247. {
  248.     register UNSIGN32 *p;
  249.     register INT16 i,j,k,ybottom,ytop;
  250.  
  251.     if (DBGOPT(DBG_PAGE_DUMP))
  252.     {
  253.     INT16 k1,k2,k3;
  254.  
  255.     for (k3 = 0; k3 < XBIT; (k3 += 7, ++p))
  256.     {    /*  print bitmap 7 words at a pass */
  257.         k1 = k3;
  258.         k2 = MIN(XBIT,k1+7);
  259.         (void)printf("prtbmap()...bitmap words %d..%d",k1,k2-1);
  260.         NEWLINE(stdout);
  261.         (void)printf("     ");
  262.         for (k = k1; k < k2; ++k)
  263.             (void)printf("%10d",k*HOST_WORD_SIZE);
  264.         NEWLINE(stdout);
  265.         for (j = YBIT-1; j >= 0; --j)
  266.         {
  267.             p = BITMAP(plane,j,0);
  268.         for (k = 0; k < XBIT; (++k,++p))
  269.         {
  270.                 if (*p)    /* print non-blank raster line */
  271.             {
  272.                 p = BITMAP(plane,j,k1);
  273.             (void)printf("%5d:",j);
  274.             for (k = k1; k < k2; (++k,++p))
  275.                 (void)printf(" %09lx",*p);
  276.             NEWLINE(stdout);
  277.             break;    /* exit loop over k */
  278.             }
  279.         }
  280.         }
  281.     }
  282.     }
  283.  
  284.     (void)clearerr(plotfp);
  285.  
  286. #if    ZAPTHISOUT
  287.     k = -1;        /* find top non-zero raster */
  288.     for (j = YBIT-1; (j > 0) && (k < 0); --j)  /* loop over raster lines */
  289.     {
  290.     p = BITMAP(plane,j,XBIT-1);
  291.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  292.         --p;        /* trim white space */
  293.     }
  294.     ytop = j;
  295. #else
  296.     ytop = YBIT-1;
  297. #endif
  298.  
  299.     k = -1;        /* find bottom non-zero raster */
  300.     for (j = 0; (j < ytop) && (k < 0); ++j) /* loop over raster lines */
  301.     {
  302.  
  303. #if    IBM_PC_MICROSOFT
  304.     for (k = XBIT - 1;((k >= 0) && (*BITMAP(plane,j,k) == 0));--k)
  305.         ;        /* trim white space */
  306. #else
  307.     p = BITMAP(plane,j,XBIT-1);
  308.     for (k = XBIT - 1; ((k >= 0) && (*p == 0)); --k)
  309.         --p;        /* trim white space */
  310. #endif
  311.  
  312.     }
  313.     ybottom = MAX(0,j-1);
  314.  
  315. #if    ZAPTHISOUT
  316.     for (j = ytop; (j >= ybottom); --j)
  317.         {
  318.     OUTF("%5d:",(int)j);
  319.         for (k = 0; k < XBIT; ++k)
  320.             OUTF(" %9x",*BITMAP(plane,j,k));
  321.     NEWLINE(plotfp);
  322.         }
  323. #endif
  324.  
  325. /*    OUTF("\033&l%dX",(int)copies);    *//* number of copies (not relevant)*/
  326.  
  327.     OUTS("\033*r4U");            /* use 4 printer colour planes */
  328.                     /* (distinct from bitmap */
  329.                     /* plane) */
  330.     OUTS("\033*v90A\033*v88B\033*v85C\033*v0I"); /* define palette # 0 as white */
  331.     OUTS("\033*v53A\033*v8B\033*v14C\033*v1I"); /* define palette # 1 */
  332.                         /* as red */
  333.     OUTS("\033*v3A\033*v26B\033*v22C\033*v2I"); /* define palette # 2 */
  334.                         /* as green */
  335.     OUTS("\033*v3I");        /* and #3 */
  336.     OUTS("\033*v4A\033*v4B\033*v29C\033*v4I"); /* define palette # 4 */
  337.                         /* as blue */
  338.     OUTS("\033*v5I\033*v6I\033*v7I"); /* and #5,6,7 */
  339.     OUTS("\033*v4A\033*v4B\033*v6C\033*v8I"); /* define palette # 8 */
  340.                         /* as black */
  341.     OUTS("\033*v9I\033*v10I\033*v11I\033*v12I\033*v13I\033*v14I\033*v15I");
  342.     /* and other values with top bit set (i.e., including black) */
  343.     OUTS("\033*r1A");            /* start plot at current */
  344.                     /* position */
  345.  
  346.     for (j = ytop; (j >= ybottom) ; --j) {    /* loop over raster lines */
  347.       for (i = 1; i<=3; i++) 
  348.     outline('V',BITMAP(i,j,0));    /* red, green, blue in order */
  349.       outline('W',BITMAP(0,j,0)); /* finish with black */
  350.     }
  351.  
  352.    /* OUTS("\033*rB");    */        /* end raster graphics */
  353.     OUTS("\f");            /* get to bottom of page */
  354.     (void)fflush(plotfp);
  355.     if (DISKFULL(plotfp))
  356.     (void)fatal("Output error -- disk storage probably full");
  357. }
  358.  
  359. #include "outrow.h"
  360. #include "prtpage.h"
  361. #include "readfont.h"
  362. #include "readgf.h"
  363. #include "readpk.h"
  364. #include "readpost.h"
  365. #include "readpxl.h"
  366. #include "reldfont.h"
  367. #include "rulepxl.h"
  368. #include "setchar.h"
  369. #include "setfntnm.h"
  370. #include "setrule.h"
  371. #include "signex.h"
  372. #include "skgfspec.h"
  373. #include "skipfont.h"
  374. #include "skpkspec.h"
  375. /* -*-C-*- special.h */
  376. /*-->special*/
  377. /**********************************************************************/
  378. /****************************** special *******************************/
  379. /**********************************************************************/
  380.  
  381. void
  382. special(s)            /* process TeX \special{} string in s[] */
  383. register char *s;
  384. {
  385.  
  386.   if (strncmp("color ",s,6)==0) {
  387.     if (strcmp("black",&s[6])==0) plane=0;
  388.     else if(strcmp("red",&s[6])==0) plane=1;
  389.     else if(strcmp("green",&s[6])==0) plane=2;
  390.     else if(strcmp("blue",&s[6])==0) plane=3;
  391.     else {
  392.       (void)sprintf(message,
  393.        "special(): colour %s not available -- ignored",s);
  394.       (void)warning(message);
  395.     }
  396.   }
  397.   else {
  398.     (void)sprintf(message,
  399.           "special():  TeX \\special{%s} not implemented in this driver",s);
  400.     (void)warning(message);
  401.   }
  402. }
  403. #include "strchr.h"
  404. #include "strcm2.h"
  405. #include "strid2.h"
  406. #include "strrchr.h"
  407. #include "tctos.h"
  408. #include "usage.h"
  409. #include "warning.h"
  410.